package com.ruoyi.edit.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.edit.domain.CourseAppendix;
import com.ruoyi.edit.service.ICourseAppendixService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程附件Controller
 * 
 * @author qiufeng
 * @date 2022-09-07
 */
@Controller
@RequestMapping("/system/courseAppendix")
public class CourseAppendixController extends BaseController
{
    private String prefix = "system/courseAppendix";

    @Autowired
    private ICourseAppendixService courseAppendixService;

    @GetMapping()
    public String courseAppendix()
    {
        return prefix + "/courseAppendix";
    }

    /**
     * 查询课程附件列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CourseAppendix courseAppendix)
    {
        startPage();
        List<CourseAppendix> list = courseAppendixService.selectCourseAppendixList(courseAppendix);
        return getDataTable(list);
    }

    /**
     * 导出课程附件列表
     */
    @Log(title = "课程附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CourseAppendix courseAppendix)
    {
        List<CourseAppendix> list = courseAppendixService.selectCourseAppendixList(courseAppendix);
        ExcelUtil<CourseAppendix> util = new ExcelUtil<CourseAppendix>(CourseAppendix.class);
        return util.exportExcel(list, "课程附件数据");
    }

    /**
     * 新增课程附件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存课程附件
     */
    @Log(title = "课程附件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CourseAppendix courseAppendix)
    {
        return toAjax(courseAppendixService.insertCourseAppendix(courseAppendix));
    }

    /**
     * 修改课程附件
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        CourseAppendix courseAppendix = courseAppendixService.selectCourseAppendixById(id);
        mmap.put("courseAppendix", courseAppendix);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程附件
     */
    @Log(title = "课程附件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CourseAppendix courseAppendix)
    {
        return toAjax(courseAppendixService.updateCourseAppendix(courseAppendix));
    }

    /**
     * 删除课程附件
     */
    @Log(title = "课程附件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(courseAppendixService.deleteCourseAppendixByIds(ids));
    }
}
